// var r;
// var AL_GAME_HUA_i18nMgr = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_i18nMgr");
// var AL_GAME_HUA_AddPrefab = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Common = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_Define");
// var AL_GAME_HUA_Instance = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_Instance");
// var AL_GAME_HUA_PopupSelf = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_EventConfig = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_EventConfig");
// var AL_GAME_HUA_GameConst = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_GoodsConfig = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_GoodsConfig");
// var AL_GAME_HUA_BankData = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_BankData");
// var AL_GAME_HUA_CurrencyData = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_CurrencyData");
// var g = cc._decorator;
// var m = g.ccclass;
// var H = g.property;
// var v =
//     (g.menu,
//     (function (e) {
//         function o() {
//             var o = (null !== e && e.apply(this, arguments)) || this;
//             o.progress_bar = null;
//             o.max_Label = null;
//             o.label_recieve = null;
//             o.money_Label = null;
//             o.desc_Label = null;
//             o.icon_Node = null;
//             return o;
//         }
//         __extends(o, e);
//         o.prototype.start = function () {
//             var e = AL_GAME_HUA_BankData.BankData.getInstance();
//             var o = AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
//             var t = AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid;
//             var n = e.huoqu_cunchu_de_jinqian();
//             var r = n / o;
//             this.max_Label.string = o.toString();
//             this.label_recieve.string = t.toString();
//             this.money_Label.string = n.toString();
//             this.desc_Label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian("银行规则", [t.toString(), o.toString()]);
//             this.progress_bar.progress = r;
//             AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showAll: !0
//             });
//         };
//         o.prototype.refresh = function () {
//             var e = AL_GAME_HUA_BankData.BankData.getInstance();
//             var o = AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
//             var t = e.huoqu_cunchu_de_jinqian();
//             var n = t / o;
//             this.money_Label.string = t.toString();
//             this.progress_bar.progress = n;
//         };
//         o.prototype.onEnable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !0
//             });
//         };
//         o.prototype.onDisable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !1
//             });
//         };
//         o.prototype.handle_button_callback = function (e, o) {
//             var t = this;
//             switch (o) {
//                 case "close":
//                     this.close();
//                     break;
//                 case "video":
//                     var n = AL_GAME_HUA_BankData.BankData.getInstance(),
//                         r = AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid,
//                         a = n.huoqu_cunchu_de_jinqian();
//                     a >= r
//                         ? AL_GAME_HUA_Common.Common.showVideo({
//                               success: function () {
//                                   n.shiyong_cunchu_de_jinqian(a);
//                                   AL_GAME_HUA_AddPrefab.AddPrefab.zhixing_feixing_jinbi({
//                                       count: 10,
//                                       fromNode: t.icon_Node,
//                                       onEnd: function () {
//                                           AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
//                                               type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
//                                               num: a
//                                           });
//                                           AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                                               source: AL_GAME_HUA_EventConfig.AssetsSource.bank,
//                                               action: AL_GAME_HUA_EventConfig.AssetsAction.video_get,
//                                               goodsList: [
//                                                   {
//                                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                                       num: a
//                                                   }
//                                               ]
//                                           });
//                                       }
//                                   });
//                                   t.refresh();
//                               }
//                           })
//                         : AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
//                               str: "金币不足x",
//                               params: [r.toString()]
//                           });
//             }
//         };
//         __decorate([H(cc.ProgressBar)], o.prototype, "progress_bar", void 0);
//         __decorate([H(cc.Label)], o.prototype, "max_Label", void 0);
//         __decorate([H(cc.Label)], o.prototype, "label_recieve", void 0);
//         __decorate([H(cc.Label)], o.prototype, "money_Label", void 0);
//         __decorate([H(cc.Label)], o.prototype, "desc_Label", void 0);
//         __decorate([H(cc.Node)], o.prototype, "icon_Node", void 0);
//         return __decorate([m], o);
//     })(AL_GAME_HUA_PopupSelf.default));
// exports.default = v;


const AL_GAME_HUA_i18nMgr = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_i18nMgr");
const AL_GAME_HUA_AddPrefab = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Common = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_Common");
const AL_GAME_HUA_Define = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_Define");
const AL_GAME_HUA_Instance = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_Instance");
const AL_GAME_HUA_PopupSelf = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_PopupSelf");
const AL_GAME_HUA_EventConfig = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_EventConfig");
const AL_GAME_HUA_GameConst = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_GameConst");
const AL_GAME_HUA_GoodsConfig = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_GoodsConfig");
const AL_GAME_HUA_BankData = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_BankData");
const AL_GAME_HUA_CurrencyData = require("../../AL_GAME_HUA/scripts/AL_GAME_HUA_CurrencyData");
const { ccclass, property, menu } = cc._decorator;

/**
 * @class
 * @extends AL_GAME_HUA_PopupSelf.default
 * @classdesc Bank UI管理类
 */
@ccclass
@menu("Custom/BankUI")
class BankUI extends AL_GAME_HUA_PopupSelf.default {
  // 组件属性定义
  @property(cc.ProgressBar)
  progress_bar = null;
  
  @property(cc.Label)
  max_Label = null;

  @property(cc.Label)
  label_recieve = null;

  @property(cc.Label)
  money_Label = null;

  @property(cc.Label)
  desc_Label = null;

  @property(cc.Node)
  icon_Node = null;

  /**
   * 启动时调用，初始化银行数据
   */
  start() {
    const bankData = AL_GAME_HUA_BankData.BankData.getInstance();
    const gameConst = AL_GAME_HUA_GameConst.GameConst.getInstance();
    const maxMoney = gameConst.money_max;
    const validMoney = gameConst.money_valid;
    const savedMoney = bankData.huoqu_cunchu_de_jinqian();
    const progress = savedMoney / maxMoney;

    this.max_Label.string = maxMoney.toString();
    this.label_recieve.string = validMoney.toString();
    this.money_Label.string = savedMoney.toString();
    this.desc_Label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian("银行规则", [
      validMoney.toString(),
      maxMoney.toString(),
    ]);
    this.progress_bar.progress = progress;
    AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
      target: this.node,
      showAll: true,
    });
  }

  /**
   * 刷新银行数据
   */
  refresh() {
    const bankData = AL_GAME_HUA_BankData.BankData.getInstance();
    const maxMoney = AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
    const savedMoney = bankData.huoqu_cunchu_de_jinqian();
    const progress = savedMoney / maxMoney;

    this.money_Label.string = savedMoney.toString();
    this.progress_bar.progress = progress;
  }

  /**
   * 组件启用时调用，发射隐藏游戏俱乐部事件
   */
  onEnable() {
    AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
      node: this.node,
      hide: true,
    });
  }

  /**
   * 组件禁用时调用，发射显示游戏俱乐部事件
   */
  onDisable() {
    AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
      node: this.node,
      hide: false,
    });
  }

  /**
   * 处理按钮点击事件
   * @param {Event} event - 事件对象
   * @param {string} action - 动作类型
   */
  handle_button_callback(event, action) {
    const bankData = AL_GAME_HUA_BankData.BankData.getInstance();
    const gameConst = AL_GAME_HUA_GameConst.GameConst.getInstance();
    const validMoney = gameConst.money_valid;
    const savedMoney = bankData.huoqu_cunchu_de_jinqian();

    switch (action) {
      case "close":
        this.close();
        break;
      case "video":
        if (savedMoney >= validMoney) {
          AL_GAME_HUA_Common.Common.showVideo({
            success: () => {
              bankData.shiyong_cunchu_de_jinqian(savedMoney);
              AL_GAME_HUA_AddPrefab.AddPrefab.zhixing_feixing_jinbi({
                count: 10,
                fromNode: this.icon_Node,
                onEnd: () => {
                  AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
                    type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
                    num: savedMoney,
                  });
                  AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
                    source: AL_GAME_HUA_EventConfig.AssetsSource.bank,
                    action: AL_GAME_HUA_EventConfig.AssetsAction.video_get,
                    goodsList: [
                      {
                        goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
                        num: savedMoney,
                      },
                    ],
                  });
                },
              });
              this.refresh();
            },
          });
        } else {
          AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
            str: "金币不足x",
            params: [validMoney.toString()],
          });
        }
        break;
      default:
        break;
    }
  }
}

exports.default = BankUI;
